package my;

import my.file.FileInfo;
import my.file.Files;
import my.set.ListSet;
import my.set.Set;
import my.set.TreeSet;
import utils.Tools;

/**
 * <p>
 * 测试
 * </p>
 *
 * @author AJun
 * @since 2020/8/31
 */
public class Main10 {

    public static void main(String[] args) {
        // testListSet();
        // testTreeSet();
        test();
    }

    /**
     * 用Set统计jdk的src源码中有多少个单词
     */
    static void test() {
        FileInfo fileInfo = Files.read("E:\\environment\\java\\src\\java\\util\\concurrent",
                new String[]{"java"});
        System.out.println("文件数量: " + fileInfo.getFiles());
        System.out.println("代码行数: " + fileInfo.getLines());
        System.out.println("单词数量(没有去重): " + fileInfo.words().length);

        // 测试时间: 添加、搜索、删除
        // Tools.calcTime("ListSet", () -> testSet(new ListSet<>(), fileInfo.words()));
        Tools.calcTime("TreeSet", () -> testSet(new TreeSet<>(), fileInfo.words()));
    }

    static void testSet(Set<String> set, String[] words) {
        for (String word : words) {
            set.add(word);
        }
        for (String word : words) {
            set.contains(word);
        }
        for (String word : words) {
            set.remove(word);
        }
    }

    static void testListSet() {
        Set<Integer> set = new ListSet<>();
        set.add(10);
        set.add(11);
        set.add(11);
        set.add(12);
        set.add(10);
        set.add(13);
        set.remove(13);
        set.traversal(new Set.Visitor<Integer>() {
            @Override
            public boolean visit(Integer element) {
                System.out.println(element);
                return false;
            }
        });
    }

    static void testTreeSet() {
        Set<Integer> set = new TreeSet<>();
        set.add(12);
        set.add(10);
        set.add(11);
        set.add(11);
        set.add(10);
        set.add(13);
        set.remove(13);
        set.traversal(new Set.Visitor<Integer>() {
            @Override
            public boolean visit(Integer element) {
                System.out.println(element);
                return false;
            }
        });
    }

}
